package com.lzy.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.dao.OrderProductMapperExt;
import com.lzy.product.dtos.OrderProductDto;
import com.lzy.product.entity.OrderProduct;
import com.lzy.product.service.OrderProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by WIN7 on 2017/11/29.
 */
@Service
public class OrderProductServiceImpl implements OrderProductService {

    @Autowired
    OrderProductMapperExt orderProductMapperExt;

    @Override
    public Long insert(OrderProductDto dto) {
        OrderProduct orderProduct = DozerUtils.map(dto, OrderProduct.class);
        return orderProductMapperExt.insertSelective(orderProduct) > 0 ? orderProduct.getOrderId() : 0L;
    }

    @Override
    public Boolean update(OrderProductDto dto) {
        return orderProductMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, OrderProduct.class)) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return orderProductMapperExt.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public Boolean remove(Long id) {
        return null;
    }

    @Override
    public OrderProductDto findById(Long id) {
        return DozerUtils.map(orderProductMapperExt.selectByPrimaryKey(id), OrderProductDto.class);
    }

    @Override
    public List<OrderProductDto> query(OrderProductDto dto) {
        return orderProductMapperExt.selectList(dto);
    }

    @Override
    public PageInfo<OrderProductDto> selectList(Pager pager, OrderProductDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<OrderProductDto> list = orderProductMapperExt.selectList(dto);
        return new PageInfo<>(list);
    }

    @Override
    public BigDecimal queryTotalSale(Long userId) {
        return orderProductMapperExt.queryTotalSale(userId);
    }

    @Override
    public Integer countList(OrderProductDto dto) {
        return orderProductMapperExt.countList(dto);
    }

    @Override
    public List<OrderProductDto> selectListByClassifyId(OrderProductDto dto, Long classifyId) {
        return orderProductMapperExt.selectListByClassifyId(dto, classifyId);
    }

    @Override
    public PageInfo<OrderProductDto> selectMemberList(Pager pager, OrderProductDto orderProductDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<OrderProductDto> list = orderProductMapperExt.selectMemberList(orderProductDto);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<OrderProductDto> selectMemberListByCond(OrderProductDto orderProductDto) {
        List<OrderProductDto> list = orderProductMapperExt.selectMemberListByCond(orderProductDto);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<OrderProductDto> selectMemberOrderList(Pager pager, OrderProductDto orderProductDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<OrderProductDto> list = orderProductMapperExt.selectMemberOrderList(orderProductDto);
        return new PageInfo<>(list);
    }

    @Override
    public Integer selectNumberByProductId(OrderProductDto dto) {
        return orderProductMapperExt.selectNumberByProductId(dto);
    }

    @Override
    public List<OrderProductDto> selectOrderProductListByMemberId(Long memberId) {
        return orderProductMapperExt.selectOrderProductListByMemberId(memberId);
    }

    @Override
    public Integer selectOrderProductCountByPayTime(String createTime,Integer cityCode) {
        return orderProductMapperExt.selectOrderProductCountByPayTime(createTime,cityCode);
    }
}
